package com.example.test_1;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class demoButton extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_button);

        /** setOnClickListener匿名内部类实现点击事件 */
        findViewById(R.id.occ2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(demoButton.this, "点击事件2成功！！", Toast.LENGTH_SHORT).show();
            }
        });

        findViewById(R.id.occ3).setOnClickListener(this);

    }

    public void occ1(View view) {
        Toast.makeText(this, "occ1", Toast.LENGTH_SHORT).show();
    }

    /**  如果界面设置了多个界面，我们应该加判断
      */
    @Override
    public void onClick(View view) {
if (R.id.occ3==1){
    Toast.makeText(this, "点击事件3成功!!!", Toast.LENGTH_SHORT).show();
        }
else {
    Toast.makeText(this, "点击事件失败!!!", Toast.LENGTH_SHORT).show();
}
    }
}